﻿/*
	Copyright © Bogdan Kobets 2011
	http://ElasticLogic.com
*/

using ElasticLogic.TagsMarker.Concepts;

namespace ElasticLogic.TagsMarker.Filter
{

	public sealed class AND : AndOr
	{
		private static readonly FilterMode mode = FilterMode.AND;

		protected override string RuleName
		{
			get { return "AND"; }
		}

		public AND(params FilterRule[] rules)
			: base(mode, rules)
		{
		}

		public AND(params Label[] labels)
			: base(mode, labels)
		{
		}

		public override FilterRule CloneRule()
		{
			FilterRule[] rules = new FilterRule[base.Count];
			int i = 0;

			foreach (FilterRule rule in this)
			{
				rules[i++] = rule.CloneRule();
			}

			return new AND(rules);
		}

		#region Operators overloading

		public static AND operator &(AND left, FilterRule right)
		{
			AND copy = (AND)left.CloneRule();
			copy.Add(right);

			return copy;
		}

		public static AND operator &(AND left, Label right)
		{
			AND copy = (AND)left.CloneRule();
			copy.Add(new NOOP(right));

			return copy;
		}

		#endregion Operators overloading

	}

}
